let db = require("../db/index");
exports.all = (req, res) => {
    var sql = "select * from household";
    db.query(sql, [], (err, data) => {        
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.floor = (req, res) => {
    var sql =
        "select * from floors";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.addfloor = (req, res) => {
    console.log (req.body.data);
    var sql =
        `insert into floors (build,house,date,unit,floor,notes) values ('${req.body.data.input}','${req.body.data.value}','${req.body.data.value1}','${req.body.data.input2}','${req.body.data.input3}','${req.body.data.textarea}')`
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.updatefloor = (req, res) => {
    console.log (req.body.data.value1);
    var sql =
        `update floors set build='${req.body.data.input}',house='${req.body.data.value}',date='${req.body.data.value1}',unit='${req.body.data.input2}',floor='${req.body.data.input3}',notes='${req.body.data.textarea}' where id=${req.body.id}`
    db.query(sql, [], (err, data) => {
        console.log(sql)
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send({
            data,
            state:200
        });
    });
};
exports.room = (req, res) => {
    var sql =
        "select * from house";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.addroom = (req, res) => {
    console.log (req.body.data);
    var sql =
        `insert into house (balcony,units,rooms,status,purpose,areas,houses) values ('${req.body.data.value}','${req.body.data.region}','${req.body.data.input}','${req.body.data.value3}','${req.body.data.value1}','${req.body.data.input3}','${req.body.data.input5}')`
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.updateroom = (req, res) => {
    console.log (req.body.data.value1);
    var sql =
        `update house set balcony='${req.body.data.value}',units='${req.body.data.region}',rooms='${req.body.data.input}',status='${req.body.data.value3}',purpose='${req.body.data.value1}',areas='${req.body.data.input3}',houses='${req.body.data.input5}' where id=${req.body.id}`
    db.query(sql, [], (err, data) => {
        console.log(sql)
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send({
            data,
            state:200
        });
    });
};
exports.delroom = (req, res) => {
    console.log(req.query);
    var sql =
        `delete from house where id = ${req.query.id}`;
    db.query(sql, (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.storage = (req, res) => {
    var sql =
        "select * from stroages";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.addstorage = (req, res) => {
    console.log (req.body.data);
    var sql =
        `insert into stroages (seat,unit1,stroage,architecture,public,practical) values ('${req.body.data.value}','${req.body.data.value1}','${req.body.data.input}','${req.body.data.input1}','${req.body.data.input2}','${req.body.data.input3}')`
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.updatestorag = (req, res) => {
    console.log (req.body.data.value1);
    var sql =
        `update stroages set seat='${req.body.data.value}',unit1='${req.body.data.value1}',stroage='${req.body.data.input}',architecture='${req.body.data.input1}',public='${req.body.data.input2}',practical='${req.body.data.input3}' where id=${req.body.id}`
    db.query(sql, [], (err, data) => {
        console.log(sql)
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send({
            data,
            state:200
        });
    });
};
exports.delstorage = (req, res) => {
    console.log(req.query);
    var sql =
        `delete from stroages where id = ${req.query.id}`;
    db.query(sql, (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.lease = (req, res) => {
    var sql =
        "select * from lease";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.region = (req, res) => {
    var sql =
        "select * from region";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.addregion = (req, res) => {
    console.log (req.body.data);
    var sql =
        `insert into region (regionname,regioncode,areasize,parkingnum,remarks) values ('${req.body.data.input}','${req.body.data.input1}','${req.body.data.input2}','${req.body.data.input3}','${req.body.data.desc}')`
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.updateregion = (req, res) => {
    console.log (req.body.data.value1);
    var sql =
        `update region set regionname='${req.body.data.input}',regioncode='${req.body.data.input1}',areasize='${req.body.data.input2}',parkingnum='${req.body.data.input3}',remarks='${req.body.data.desc}' where id=${req.body.id}`
    db.query(sql, [], (err, data) => {
        console.log(sql)
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send({
            data,
            state:200
        });
    });
};
exports.delregion = (req, res) => {
    console.log(req.query);
    var sql =
        `delete from region where id = ${req.query.id}`;
    db.query(sql, (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.pay = (req, res) => {
    var sql =
        "select * from pay";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.pay = (req, res) => {
    var sql =
        "select * from pay";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.lot = (req, res) => {
    var sql =
        "select * from lot";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.addlot = (req, res) => {
    console.log (req.body.data);
    var sql =
        `insert into lot (area,spotnumber,areasize,floor,spottype,spotstatus) values ('${req.body.data.value}','${req.body.data.input}','${req.body.data.input1}','${req.body.data.input2}','${req.body.data.value1}','${req.body.data.value2}')`
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.updatelot = (req, res) => {
    console.log (req.body.data.value1);
    var sql =
        `update lot set area='${req.body.data.value}',spotnumber='${req.body.data.input}',areasize='${req.body.data.input1}',floor='${req.body.data.input2}',spottype='${req.body.data.value1}',spotstatus='${req.body.data.value2}' where id=${req.body.id}`
    db.query(sql, [], (err, data) => {
        console.log(sql)
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send({
            data,
            state:200
        });
    });
};
// exports.dellot = (req, res) => {
//     console.log(req.query);
//     var sql =
//         `delete from lot where id = ${req.query.id}`;
//     db.query(sql, (err, data) => {
//         if (err) {
//             console.log("出错了", err);
//             return res.send("错误" + err.message);
//         }
//         res.send(data);
//     });
// };
exports.vehicle = (req, res) => {
    var sql =
        "select * from vehicle";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.card = (req, res) => {
    var sql =
        "select * from card";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.addcard = (req, res) => {
    console.log (req.body.data);
    var sql =
        `insert into card (cardnumber,owner1,platenumber) values ('${req.body.data.input}','${req.body.data.input1}','${req.body.data.input3}')`
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.updatecard = (req, res) => {
    console.log (req.body.data.value1);
    var sql =
        `update card set cardnumber='${req.body.data.input}',owner1='${req.body.data.input1}',platenumber='${req.body.data.input3}' where id=${req.body.id}`
    db.query(sql, [], (err, data) => {
        console.log(sql)
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send({
            data,
            state:200
        });
    });
};
exports.visitor = (req, res) => {
    var sql =
        "select * from visitor";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.complaint = (req, res) => {
    var sql =
        "select * from complaint";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.activity = (req, res) => {
    var sql =
        "select * from activity";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.notice = (req, res) => {
    var sql =
        "select * from notice";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.charge = (req, res) => {
    var sql =
        "select * from charge";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.cycle = (req, res) => {
    var sql =
        "select * from cycle";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.classification = (req, res) => {
    var sql =
        "select * from classification";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.maintenance = (req, res) => {
    var sql =
        "select * from maintenance";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.record = (req, res) => {
    var sql =
        "select * from record";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.mission = (req, res) => {
    var sql =
        "select * from mission";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.plan = (req, res) => {
    var sql =
        "select * from plan";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.points = (req, res) => {
    var sql =
        "select * from points";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.routes = (req, res) => {
    var sql =
        "select * from routes";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.project = (req, res) => {
    var sql =
        "select * from project";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.daily = (req, res) => {
    var sql =
        "select * from daily";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.weekly = (req, res) => {
    var sql =
        "select * from weekly";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.monthly = (req, res) => {
    var sql =
        "select * from monthly";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.business = (req, res) => {
    var sql =
        "select * from business";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.resident = (req, res) => {
    var sql =
        "select * from resident";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.complain = (req, res) => {
    var sql =
        "select * from complain";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.facilities = (req, res) => {
    var sql =
        "select * from facilities";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.staff = (req, res) => {
    var sql =
        "select * from staff";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.role = (req, res) => {
    var sql =
        "select * from role";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.log = (req, res) => {
    var sql =
        "select * from log";
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.del = (req, res) => {
    console.log(req.query);
    // const tableName = deleteRoutes[req.params.table];
    // console.log(tableName);
    var sql =
        `delete from lot where id = ${req.query.id}`;
    db.query(sql, (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.search = (req, res) => {
    var sql =
        `select * from activity where activitytitle like '%${req.query.activitytitle}%'`;
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.search1 = (req, res) => {
    var sql =
        `select * from stroages where stroage like '%${req.query.stroage}%'`;
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
exports.search2 = (req, res) => {
    var sql =
        `select * from notice where title like '%${req.query.title}%'`;
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
//详情渲染
exports.detail = (req, res) => {
    
};
// exports.new = (req, res) => {
//     var sql =
//         `insert into floors (build,house,date,unit,floor,notes) values()`;
//     db.query(sql, [], (err, data) => {
//         if (err) {
//             console.log("出错了", err);
//             return res.send("错误" + err.message);
//         }
//         res.send(data);
//     });
// };

// //删除人员
// exports.del = (req, res) => {
//     var sql = "delete from t_user where id = ?";
//     db.query(sql, [req.body.id], (err, data) => {
//         if (err) {
//             console.log("出错了", err);
//             return res.send("错误" + err);
//         }
//         res.send(data);
//     });
// };

// //更新
// exports.update = (req, res) => {
//     var sql =
//         "update t_user set name = ?,mobile=?,idNo=?,sex=?,noteText=?,groupId=? where id = ?";
//     db.query(
//         sql,
//         [
//             req.body.name,
//             req.body.mobile,
//             req.body.idNo,
//             req.body.sex,
//             req.body.noteText,
//             req.body.groupId,
//             req.body.id,
//         ],
//         (err, data) => {
//             if (err) {
//                 console.log("出错了", err);
//                 return res.send("错误" + err);
//             }
//             res.send(data);
//         }
//     );
// };